package com.jd.xianghairui.jimdb;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;

/**
 * @autoor: xianghairui
 * @Date: Create in 19:53 2017/11/17
 * @Description:
 */
@Service
public class JimClientCacheDemo {

    private static final Logger logger = LoggerFactory.getLogger(JimClientCacheDemo.class);

    @Cacheable(value = "cachetest_", key = "#key")
    public String getMessage(String key) {
        logger.info("get key[{}] from db...", key);
        return "msg";
    }

    @CachePut(value = "cachetest_", key = "#key")
    public String setMessage(String key, String message) {
        logger.info("set key[{}] value[{}] ...",key, message);
        return message;
    }

    @Caching(evict = {@CacheEvict(value = "cachetest_", key = "#key")})
    public boolean delete(String key) {
        logger.info("delete key[{}] ...", key);
        return true;
    }

}
